package com.yiyibook.controller;

import com.yiyibook.util.FileUploadUtil;
import com.yiyibook.util.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

/**
 * 测试 Controller
 *
 * @author yi.wu 2019-11-04 19:41:30
 */
@Controller
@RequestMapping("/test")
public class TestController {

    @Autowired
    private FileUploadUtil fileUploadUtil;

    @PostMapping("/upload")
    public ModelAndView uploadFile(MultipartFile uploadFile){
        ModelAndView mv = new ModelAndView();
        mv.setViewName("yiyibook/manager/test");
        Msg msg = fileUploadUtil.uploadFile(uploadFile);
        int code = msg.getCode();
        if(code == Msg.SUCCESS){
            mv.addObject("fileTrueName", msg.getExtend().get("fileTrueName"));
        }else if(code == Msg.FAIL){
            mv.addObject("fileTrueName",null);
        }
        return mv;
    }

}
